﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tssipl.PaymentAdapter.Core;
using Tssipl.PaymentAdapter.MessageFormat.Sfms;
namespace Tssipl.PaymentAdapter.MessageEntity.Sfms.Rtgs
{
    public class RtgsDebitNotification :SfmsMessageEntityBase
    {
        public string TRN { get; set; }//16x //M
        public string RelatedReference { get; set; }        //16x //M
        public string SettlementAccountNumber { get; set; }        //35x //M

        private string _ValueDate_Currency_Amount { get; set; }//8!n3!a19d  //M
        public DateTime ValueDate { get; set; }
        public string Currency { get; set; }
        public decimal Amount { get; set; }

        public string OrderingInstitution1 { get; set; }//4!a1!n6!a 
        public string OrderingInstitution2 { get; set; }//[/1!a][/34x] 4*35x 

        public string SenderToReceiverInformation { get; set; }//6*35x

        public RtgsDebitNotification(MessageParseResults results)
            : base(results)
        {
            SfmsMessage message = (SfmsMessage)results.getMessage();
            SfmsBlock4 block4 = message.getBlock4();
            this.TRN = block4.getField("2020").Trim();

            this.RelatedReference = block4.getField("2006");
            this.SettlementAccountNumber = block4.getField("6116");

            this._ValueDate_Currency_Amount = block4.getField("4488");
            this.ValueDate = DateTime.ParseExact(this._ValueDate_Currency_Amount.Substring(0, 8), "yyyyMMdd", null);
            this.Currency = this._ValueDate_Currency_Amount.Substring(8, 3);
            this.Amount = decimal.Parse(this._ValueDate_Currency_Amount.Substring(11, this._ValueDate_Currency_Amount.Length - 11).Replace(",", "."));

            this.OrderingInstitution1 = block4.getField("5517");
            this.OrderingInstitution2 = block4.getField("5516"); 

            this.SenderToReceiverInformation = block4.getField("7495");
        }
    }
}
